home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
ctutor.exe
/
ANSWERS
/
CH05_3.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-15
|
1KB
|
56 lines
/* Chapter 5 - Program 1 - SUMSQRES.C */
#include "stdio.h"
void header(void);
void square(int number);
void ending(void);
int sum; /* This is a global variable */
void main(void)
{
int index;
header(); /* This calls the function named header */
for (index = 1 ; index <= 7 ; index++)
square(index); /* This calls the square function */
ending(); /* This calls the ending function */
}
void header(void) /* This is the function named header */
{
sum = 0; /* Initialize the variable "sum" */
printf("This is the header for the square program\n\n");
}
void square(int number) /* This is the square function */
{
int numsq;
numsq = number * number; /* This produces the square */
sum += numsq;
printf("The square of %d is %d\n", number, numsq);
}
void ending(void) /* This is the ending function */
{
printf("\nThe sum of the squares is %d\n", sum);
}
/* Result of execution
This is the header for the square program
The square of 1 is 1
The square of 2 is 4
The square of 3 is 9
The square of 4 is 16
The square of 5 is 25
The square of 6 is 36
The square of 7 is 49
The sum of the squares is 140
*/